# -*- coding: UTF-8 -*-
import os
import re
from lxml import etree
from itertools import islice
html_filename='./git/git命令手册.html'
template_html_filename='./template.html'


html=etree.parse(html_filename,etree.HTMLParser())


title=str(html.xpath('//title')[0].text)
print("标题为：",title)
path,filename=os.path.split(html_filename)
# print(path)
html_filename_re=path+"/md_"+filename
print(html_filename_re)
with open(html_filename_re,'w',encoding="utf-8") as f_html:
    with open(template_html_filename,'r',encoding="utf-8") as f_template:
        for line in islice(f_template,0,4):
            f_html.write(line)
        title_html="<title>"+title+"</title>\n"
        f_html.write(title_html)
        for line in islice(f_template,0,None):
            f_html.write(line)
        with open(html_filename,'r',encoding="utf-8") as f_tmp:
            flag=False
            for line in islice(f_tmp,0,None):
                if line.startswith('<body') or flag:
                    flag=True
                    f_html.write(line)
                    print(132456)

                    

        
